// pages/teamList/teamList.js
import Toast from '@vant/weapp/toast/toast';
const app = getApp();
let timer; 
//teamAuditMembers
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight: null,
    data: [],
    dialogVisible: false,
    refuseVisible: false,
    refuseText: '',
    memberId: '',
    allow: null,
    type: null,
    pageIndex: 1,
    pageSize: 15
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(wx.getSystemInfoSync().windowHeight);
    this.setData({
      type: options.type,
      scrollHeight: wx.getSystemInfoSync().windowHeight + 'rpx'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.init();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  lower(e) {
    console.log(e)
  },
  scroll(e) {
    timer && clearTimeout(timer);
    timer = setTimeout(_=>{
      let deltaY = e.detail.deltaY < 0;
      if(deltaY) {
        this.setData({
          pageIndex: this.data.pageIndex + 1
        })
        this.init();
      }
    },300);
  },
  init() {
    let type = this.data.type === 'all' ? 1 : 2;
    let pageIndex = this.data.pageIndex;
    let pageSize = this.data.pageSize;
    app.$request.teamChildren({type,pageIndex,pageSize})  //teamMembers
    .then(res => {
      if(res.code === 1) {
        if(res.data.result.length > 0) {
          this.setData({
            data: [...this.data.data,...res.data.result]
          })
        }
      }
    })
  }
})